home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4062 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: #define, question from a beginner
  5. Date: 01 Feb 1996 16:56:41 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb1095641@qcd.lanl.gov>
  8. References: <ma-010296161301@mac147.maths.uwa.edu.au> <31109AF8.423B@zess.uni-siegen.de>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: Markus Becker's message of Thu, 01 Feb 1996 11:50:32 +0100
  13.  
  14. In article <31109AF8.423B@zess.uni-siegen.de> Markus Becker
  15. <becker@zess.uni-siegen.de> writes: 
  16. <snip>
  17.    ma wrote:
  18.    snip
  19.    > I can use #define to replace single lines#14 and 18. The
  20. following works.
  21.  
  22.    > QUESTION: Can I use one single macro fiveLines to replace lines
  23. from 14 to
  24.    > 18 inclusively? I tried the following but got rejected. Is there
  25. any way to
  26.    > get around it? Note that lines 14 and 18 contain local variables.
  27.  
  28.    You must use the "line-continuation" character -> "\"
  29.    to continue a macro over more than one line.
  30.  
  31.    > #define fiveLines printf("%d, ",j); \ // macro should include
  32. this first ==== here
  33.    > /* comment is part of the macro \ // <- and here
  34.    > the comment contains a few lines \ // <- and here
  35.  
  36.    and so on.
  37.  
  38. First, it is useless to discuss the code as it stands: this is a C
  39. language newsgroup and // does _not_ start a comment in C. What would
  40. have happened if it did is beyond me ... there is a group which
  41. discusses the language where C++ is discussed: you can ask there if
  42. you please.
  43.  
  44. Second, a comment can never be a part of a macro, because each comment
  45. is treated as a single space before macros are recognized or
  46. expanded. (Or rather, by the `as if' rule: the _meaning_ of the
  47. program is as if the comments were replaced by spaces early on.) The \
  48. followed by newline (NOT \ followed by spaces followed by newline or \
  49. followed by // or other junk) is deleted even before the comment
  50. processing (but after the trigraph processing so that ??/ followed by
  51. newline is as good as \ followed by newline).
  52.  
  53. The macro definition must appear on one line at the end of all
  54. this. So, remembering that comments are already removed, you do not
  55. need to put the line continuations inside a comment. Thus, the
  56. following is correct
  57.  
  58. #define fiveLines printf("%d, ",j); \
  59.                   /* comment
  60.                      continues
  61.                      still */ \
  62.                   printf("%d, ",k);
  63.  
  64. Cheers
  65. Tanmoy
  66. --
  67. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  68. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  69. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  70. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  71. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  72. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  73.